package logic

import (
	"context"
	"course-admin/model"
	"errors"

	"course-admin/userrpc/internal/svc"
	"course-admin/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectDelLogic {
	return &CollectDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 取消收藏
func (l *CollectDelLogic) CollectDel(in *userrpc.CollectDelRequest) (*userrpc.CollectDelResponse, error) {
	// todo: add your logic here and delete this line
	var findUser model.User

	if err := findUser.FindUserById(model.DB, in.UserId); err != nil {
		return nil, err
	}
	if findUser.ID == 0 {
		return nil, errors.New("用户不存在")
	}
	var findGoods model.Goods
	if err := findGoods.FindGoodsById(model.DB, in.GoodsId); err != nil {
		return nil, err
	}
	if findGoods.ID == 0 {
		return nil, errors.New("商品不存在")
	}
	var collect model.Collect

	if err := collect.CollectDel(model.DB, in); err != nil {
		return nil, errors.New("删除失败")
	}
	return &userrpc.CollectDelResponse{}, nil
}
